package com.example.prom.ok.y2023.work.tencentCloud;
import com.alibaba.fastjson.JSON;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
//导入可选配置类
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
// 导入对应SMS模块的client
import com.tencentcloudapi.sms.v20210111.SmsClient;
// 导入要请求接口对应的request response类
import com.tencentcloudapi.sms.v20210111.models.*;

/**
 * Tencent Cloud Sms PullSmsSendStatus
 *
 */
public class PullSmsSendStatus {
    public static void main(String[] args) {
        try {

            Credential cred = new Credential("IKIDzsdBa0QT3wnRyNYYTkN0VVSXg0cBh5LV", "BMXaWfcxBMW1N1gTUey7hFb5eAk2FOUO");
            // 实例化一个http选项，可选，没有特殊需求可以跳过
            HttpProfile httpProfile = new HttpProfile();
            // 设置代理
            // httpProfile.setProxyHost("真实代理ip");
            // httpProfile.setProxyPort(真实代理端口);
            /* SDK默认使用POST方法。
             * 如果你一定要使用GET方法，可以在这里设置。GET方法无法处理一些较大的请求 */
            httpProfile.setReqMethod("POST");
            /* SDK有默认的超时时间，非必要请不要进行调整
             * 如有需要请在代码中查阅以获取最新的默认值 */
            httpProfile.setConnTimeout(60);
            /* SDK会自动指定域名。通常是不需要特地指定域名的，但是如果你访问的是金融区的服务
             * 则必须手动指定域名，例如sms的上海金融区域名： sms.ap-shanghai-fsi.tencentcloudapi.com */
            httpProfile.setEndpoint("sms.tencentcloudapi.com");
            /* 非必要步骤:
             * 实例化一个客户端配置对象，可以指定超时时间等配置 */
            ClientProfile clientProfile = new ClientProfile();
            /* SDK默认用TC3-HMAC-SHA256进行签名
             * 非必要请不要修改这个字段 */
            clientProfile.setSignMethod("HmacSHA256");
//            clientProfile.setHttpProfile(httpProfile);
            SmsClient client = new SmsClient(cred, "ap-singapore", clientProfile);

            PullSmsSendStatusRequest req = new PullSmsSendStatusRequest();
            PullSmsReplyStatusRequest request = new PullSmsReplyStatusRequest();
            request.setLimit(5L);
            request.setSmsSdkAppId("2400001119");
            PullSmsReplyStatusResponse response = client.PullSmsReplyStatus(request);
            System.out.println(JSON.toJSONString(response));

            /* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId，示例如1400006666 */
            String sdkAppId = "2400001119";
            req.setSmsSdkAppId(sdkAppId);
            // 设置拉取最大条数，最多100条
            Long limit = 5L;
            req.setLimit(limit);
            /* 通过 client 对象调用 PullSmsSendStatus 方法发起请求。注意请求方法名与请求对象是对应的
             * 返回的 res 是一个 PullSmsSendStatusResponse 类的实例，与请求对象对应 */
            PullSmsSendStatusResponse res = client.PullSmsSendStatus(req);
            System.out.println(JSON.toJSONString(res));
            PullSmsSendStatusByPhoneNumberRequest smsSendStatusByPhoneNumberRequest = new PullSmsSendStatusByPhoneNumberRequest();
            smsSendStatusByPhoneNumberRequest.setPhoneNumber("+85253728468");
            smsSendStatusByPhoneNumberRequest.setLimit(2L);
            smsSendStatusByPhoneNumberRequest.setSmsSdkAppId(sdkAppId);
            smsSendStatusByPhoneNumberRequest.setBeginTime(1678762664L);
            smsSendStatusByPhoneNumberRequest.setEndTime(1678765664L);
            smsSendStatusByPhoneNumberRequest.setOffset(0L);
            PullSmsSendStatusByPhoneNumberResponse pullSmsSendStatusByPhoneNumberResponse = client.PullSmsSendStatusByPhoneNumber(smsSendStatusByPhoneNumberRequest);
            System.out.println(JSON.toJSONString(pullSmsSendStatusByPhoneNumberResponse));
            PullSmsReplyStatusByPhoneNumberRequest smsReplyStatusByPhoneNumberRequest = new PullSmsReplyStatusByPhoneNumberRequest();
            smsReplyStatusByPhoneNumberRequest.setPhoneNumber("+85253728468");
            smsReplyStatusByPhoneNumberRequest.setLimit(2L);
            smsReplyStatusByPhoneNumberRequest.setSmsSdkAppId(sdkAppId);
            smsReplyStatusByPhoneNumberRequest.setBeginTime(1678762664L);
            smsReplyStatusByPhoneNumberRequest.setEndTime(1678765664L);
            smsReplyStatusByPhoneNumberRequest.setOffset(0L);
            PullSmsReplyStatusByPhoneNumberResponse pullSmsReplyStatusByPhoneNumberResponse = client.PullSmsReplyStatusByPhoneNumber(smsReplyStatusByPhoneNumberRequest);
            System.out.println(JSON.toJSONString(pullSmsReplyStatusByPhoneNumberResponse));

        } catch (TencentCloudSDKException e) {
            e.printStackTrace();
        }
    }
}
